package com.wan37.gate.utils;

import com.wan37.gate.domain.ClientConnection;
import com.wan37.protobuf.message.client2server.auth.Auth;
import com.wan37.protobuf.message.client2server.game.Game;
import com.wan37.protobuf.util.ServerProtoUtils;
import io.netty.buffer.ByteBuf;

/**
 * @author : luoyong
 * @date : 2020-05-27 10:36
 **/
public class RouteUtils {
    /**
     * 向客户端发送返回的消息.
     *
     * @param code
     * @param content
     * @param clientConnection
     */
    public static void sendResponse(int code, String content, ClientConnection clientConnection) {

        Auth.SResponse.Builder sb = Auth.SResponse.newBuilder();
        sb.setCode(code);
        sb.setContent(content);
        Auth.SResponse sResponse = sb.build();

        //sResponse消息
        ByteBuf sendBuf = ServerProtoUtils.pack2Client(sResponse);

        //发给客户端.
        clientConnection.getCtx().writeAndFlush(sendBuf);
    }


    /**
     * 给消息发送者回话
     */
    public static void sendResponse2Sender(int code, String content, ClientConnection clientConnection) {

        Game.SResponse.Builder sb = Game.SResponse.newBuilder();
        sb.setCode(code);
        sb.setContent(content);
        Game.SResponse sResponse = sb.build();

        ByteBuf sendBuf = ServerProtoUtils.pack2Client(sResponse);

        //发给客户端
        clientConnection.getCtx().writeAndFlush(sendBuf);
    }
}
